package com.lionel.websocket.redis;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lionel.websocket.redis.entity.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sun.nio.cs.US_ASCII;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("redis")
public class RedisController {
    @Autowired
    private RedisUtil redisUtil;
    @GetMapping("test")
    public String test() {
        for (int i = 0; i < 10; i++) {
            UserDto userDto = new UserDto();
            userDto.setAge("11"+i);
            userDto.setName("zss");
            String user = JSON.toJSONString(userDto);
            redisUtil.lRightPush("users",user);
        }
        return "success";
    }

    @GetMapping("get/{name}")
    public String get(@PathVariable(value = "name") String name) {
        List<String> list = redisUtil.lRange(name, 0, -1);
//        JSONObject jsonObject = JSONObject.parseObject(user);
//        UserDto userDto = JSON.parseObject(user, UserDto.class);
        return list.toString();
    }
}
